import Vue from 'vue'
import Vuex from 'vuex'
import tab from './tab'

Vue.use(Vuex)

const getDay = function() {
    var now = new Date();
    // 年月日
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    month = month < 10 ? "0" + month : month; //变个位数时补个0
    var date = now.getDate();
    date = date < 10 ? "0" + date : date;
    return year + "年" + month + "月" + date + "日";
}

const getTime = function() {
    var now = new Date();
    // 年月日
    var hours = now.getHours();
    hours = hours < 10 ? "0" + hours : hours; //变个位数时补个0
    var min = now.getMinutes();
    min = min < 10 ? "0" + min : min; //变个位数时补个0
    var sec = now.getSeconds();
    sec = sec < 10 ? "0" + sec : sec;
    return hours + ":" + min + ":" + sec;
}
export default new Vuex.Store({
    state: {
        day: getDay(),
        time: getTime(),
        counter: 0,
    },
    mutations: {
        // 方法
        add(state) {
            state.counter++
        },
        sub(state) {
            state.counter--;
        },
        updateDay(state) {
            state.day = getDay();
        },
        updateTime(state) {
            state.time = getTime();
        }
    },
    modules: {
        tab,
    }
})